<!--
 * @Description: 版本记录
 * @Author: wind-lc
 * @version: 1.0
 * @Date: 2022-02-16 17:44:21
 * @LastEditTime: 2022-04-06 15:17:14
 * @FilePath: \cscec-pms-admin\src\views\project\projectManagementPlanning\projectManagementPlanningSchedule\components\VersionRecord.vue
-->
<template>
  <BaseModal
    :visible="visible"
    title="版本记录"
    :width="1200"
    destroy-on-close
    @cancel="handleModalCancel"
  >
    <s-table
      ref="table"
      row-key="id"
      :columns="columns1"
      :data="loadData"
      :alert="true"
      show-size-changer
      show-quick-jumper
      :show-pagination="false"
      :scroll="{ y: 400 }"
      bordered
    >
      <template
        slot="operation"
        slot-scope="text, record"
      >
        <a @click="handleDetail(record)">查看详情</a>
      </template>
    </s-table>
    <template slot="footer">
      <a-button @click="handleModalCancel">
        关闭
      </a-button>
    </template>
  </BaseModal>
</template>
<script>
import BaseModal from '@/components/BaseModal'
import { columns1 } from '../model.js'
import { list } from '@/api/projectManagementPlanning/projectManagementPlanningSchedule'
import { view } from '@/api/project/plannManagement/plannTableSummary'
import { pageName } from '../../projectManagementPlanningComponents/components/model.js'
import { pageName as pageName1 } from '../../../plannManagement/plannTable/model.js'
export default {
  name: 'VersionRecord',
  props: {
    // 隐藏显示
    visible: {
      type: Boolean,
      require: true
    },
    // 版本记录信息
    data: {
      type: Object,
      require: true
    }
  },
  components: {
    BaseModal
  },
  data() {
    return {
      // 表头
      columns1
    }
  },
  methods: {
    /**
     * @description: 表格数据加载方法
     * @param {Object} parameter 分页信息
     * @return {Promise} 接口Promise
     */
    async loadData(parameter) {
      try {
        let res = void 0
        // 通过type判断 type为1是工程策划新的表，否则是项目策划的表
        if (this.data.type === 1) {
          res = await view.querySchemeVersionList({ detailId: this.data.id })
          if (res.code === 200) {
            return Promise.resolve({
              code: 200,
              data: res.data.map((el) => {
                const item = JSON.parse(JSON.stringify(el))
                item.versionCreateTime = el.fillTime
                item.versionOperator = el.fillName
                return item
              })
            })
          } else {
            return Promise.reject()
          }
        } else {
          res = await list.queryPlanTaskVersionList({ planTaskDetailId: this.data.id })
          if (res.code === 200) {
            return Promise.resolve(res)
          } else {
            return Promise.reject()
          }
        }
      } catch (error) {
        console.log(error)
        return Promise.reject()
      }
    },
    /**
     * @description: 查看详情
     * @param {object} record 行数据
     * @return {void}
     */
    handleDetail(record) {
      const { version } = record
      const { id, code } = this.data
      this.handleModalCancel()
      // 通过type判断 type为1是工程策划新的表，否则是项目策划的表
      if (this.data.type === 0 || this.data.type === undefined) {
        // 项目策划
        if (this.data?.isAudit) {
          let routeData = this.$router.resolve({
            path: '/process/auditBusinessDetail',
            query: {
              detailUrl: '/project/projectManagementPlanning/projectManagementPlanningComponents',
              id,
              pageType: 'detail',
              editModel: 0,
              pageName: pageName[code - 1],
              version
            }
          })
          window.open(routeData.href, '_blank')
        } else {
          this.$router.push({
            path: '/project/projectManagementPlanning/projectManagementPlanningComponents',
            query: {
              id,
              pageType: 'detail',
              editModel: 0,
              pageName: pageName[code - 1],
              version
            }
          })
        }
      } else {
        // 工程策划
        if (this.data?.isAudit) {
          let routeData = this.$router.resolve({
            path: '/process/auditBusinessDetail',
            query: {
              detailUrl: '/project/plannManagement/plannTableComponents',
              id,
              pageType: 'detail',
              editModel: 0,
              pageName: pageName1[code - 26]
            }
          })
          window.open(routeData.href, '_blank')
        } else {
          this.$router.push({
            path: '/project/plannManagement/plannTableComponents',
            query: {
              id,
              pageType: 'detail',
              editModel: 0,
              pageName: pageName1[code - 26]
            }
          })
        }
      }
    },
    /**
     * @description: 关闭模态框
     * @param {void}
     * @return {void}
     */
    handleModalCancel() {
      this.$emit('update:visible', false)
    }
  }
}
</script>
<style lang="less" scoped>
@deep: ~'>>>';
@{deep} .ant-table-fixed {
  margin-left: 0;
}
</style>
